home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetWarmer / source / Cursors.c next >
Encoding:
C/C++ Source or Header  |  1992-06-11  |  1.8 KB  |  83 lines  |  [TEXT/KAHL]

  1. /* © 1988, Bowers Development Corp. */
  2. /* Cursors.c */
  3.  
  4. #include "Globals.h"    
  5. #include "ResourceDefs.h"    
  6.  
  7. #include "Cursors.h"
  8.  
  9. RgnHandle            cursorRgn;
  10. CursHandle            watch;
  11.  
  12.  
  13. CursHandle            iBeam;
  14.  
  15. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  16. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  17.  
  18. /*----------*/
  19. void LoadCursors ()
  20. {
  21.     watch = GetCursor (watchCursor);
  22.     iBeam = GetCursor (iBeamCursor);
  23.  
  24.     cursorRgn = NewRgn ();
  25.  
  26.     InitCursor ();
  27. } /*LoadCursors*/
  28.  
  29. /*----------*/
  30. void GlobalRectRgn (RgnHandle    destRegion,
  31.                     Rect        sourceRect);
  32. void GlobalRectRgn (destRegion, sourceRect)
  33. RgnHandle        destRegion;
  34. Rect            sourceRect;
  35. {
  36.     LocalToGlobal (&TopLeft (sourceRect)); 
  37.     LocalToGlobal (&BotRight (sourceRect));
  38.     RectRgn (destRegion, &sourceRect);
  39. } /*GlobalRectRgn*/
  40.  
  41. /*----------*/
  42. void ShapeCursor ()
  43. {
  44.     WindowPtr        front;
  45.     WindowPeek        frontPeek;
  46.     RgnHandle        arrowRgn;
  47.     RgnHandle        iBeamRgn;
  48.     Point            mousePoint;
  49.     Rect            textRect;
  50.     
  51.     front = FrontWindow ();
  52.     frontPeek = (WindowPeek) front;
  53.     if (inBackground) {
  54.         /*let foreground set cursor*/
  55.     } else if ((front != nil) && (frontPeek->windowKind < 0)) {
  56.         /*let da set its own cursor*/
  57.     } else { 
  58.         arrowRgn = NewRgn ();
  59.         iBeamRgn = NewRgn ();
  60.         RectRgn (arrowRgn, &screenBits.bounds);
  61.         mousePoint = curEvent.where;
  62.         if (front == nil) {
  63.             /*arrow*/
  64.         } else if (front == curWindow) {
  65.             SetPort (curWindow);    /*for local-to-global*/
  66.             if (cur->text != nil) {
  67.                 textRect = (**(cur->text)).viewRect;
  68.                 GlobalRectRgn (iBeamRgn, textRect);
  69.             }
  70.             DiffRgn (arrowRgn, iBeamRgn, arrowRgn);
  71.         }
  72.         if (PtInRgn (mousePoint, iBeamRgn)) {
  73.             SetCursor (&(**iBeam));
  74.             CopyRgn (iBeamRgn, cursorRgn);
  75.         } else {
  76.             SetCursor (&arrow);
  77.             CopyRgn (arrowRgn, cursorRgn);
  78.         }
  79.         DisposeRgn (arrowRgn);
  80.         DisposeRgn (iBeamRgn);
  81.     }
  82. } /*ShapeCursor*/
  83.